/**
 * Notes: 预约模块业务逻辑
 * Ver : CCMiniCloud Framework 2.0.1 ALL RIGHTS RESERVED BY cclinux0730 (wechat)
 * Date: 2025-12-10 07:48:00
 */

const BaseBiz = require('./base_biz.js');
const cloudHelper = require('../../helper/cloud_helper.js');
const pageHelper = require('@/utils/helper/page_helper.js');
const api = require('@/api/api.js');

class FavBiz extends BaseBiz {
    static async isFav(that, oid, type = '') {
        if (!oid) {
            return;
        }
        that.setData({
            isFav: -1
        });

        // 异步获取是否收藏
        let params = {
            relatedId: oid,
            relatedType: type
        };
        api.checkFav(params).then((result) => {
            console.log('result', result);
            that.setData({
                isFav: result == true ? 1 : 0
            });
        });
        // cloudHelper
        //     .callCloudSumbit('fav/is_fav', params, {
        //         title: 'bar'
        //     })
        //     .then((result) => {
        //         that.setData({
        //             isFav: result.data.isFav
        //         });
        //     })
        //     .catch((error) => {});
    }
    static async updateFav(that, oid, isFav, type, title) {
        let path = pageHelper.getCurrentPageUrlWithArgs();
        if (!oid || !path || !title || !type) {
            return;
        }
        let params = {
            relatedId: oid,
            title: title,
            relatedType: type,
            path: path
        };
        let opts = {
            title: isFav == 0 ? '收藏中' : '取消中'
        };
        try {
            if (isFav == 0) {
                api.addFav(params).then((result) => {
                    that.setData({
                        isFav: 1
                    });
                });
            } else {
                api.removeFav(params).then((result) => {
                    that.setData({
                        isFav: 0
                    });
                });
            }
            // let result = await cloudHelper.callCloudSumbit('fav/update', params, opts);
            // that.setData({
            //     isFav: result.data.isFav
            // });
        } catch (e) {
            console.log('CatchClause', e);
            console.log('CatchClause', e);
            console.log(e);
        }
    }
}
module.exports = FavBiz;
